package com.ssy.lingxi.system.controller;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.system.dto.request.*;
import com.ssy.lingxi.system.dto.response.PlatformProcessResponse;
import com.ssy.lingxi.system.dto.response.RoleResponse;
import com.ssy.lingxi.system.entity.Role;
import com.ssy.lingxi.system.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 会员角色权限设置-会员角色设置
 * @author wrc
 * @date 2020/7/20
 */
@Api(tags = "会员角色权限设置-会员角色设置")
@RestController
public class RoleController {
    @Resource
    private RoleService roleService;

    @ApiOperation(value = " 查询系统角色列表")
    @GetMapping("/role/list")
    public Wrapper<PageData<RoleResponse>> roleList(RoleRequest roleRequest) {
        return roleService.roleList(roleRequest);
    }

    @ApiOperation(value = " 添加系统角色")
    @PostMapping("/role/add")
    public Wrapper<Role> roleAdd(@RequestBody RoleAddRequest request) {
        synchronized (RoleController.class) {
            return roleService.roleAdd(request);
        }
    }

    @ApiOperation(value = " 修改系统角色")
    @PostMapping("/role/update")
    public Wrapper<Void> roleUpdate(@RequestBody RoleUpdateRequest request) {
        synchronized (RoleController.class) {
            return roleService.roleUpdate(request);
        }
    }

    @ApiOperation(value = " 停用系统角色")
    @PostMapping("/role/stop")
    public Wrapper<Void> roleStop(@RequestBody RoleStopRequest request) {
        synchronized (RoleController.class) {
            return roleService.roleStop(request);
        }
    }

    @ApiOperation(value = " 启用系统角色")
    @PostMapping("/role/start")
    public Wrapper<Void> roleStart(@RequestBody RoleStopRequest request) {
        synchronized (RoleController.class) {
            return roleService.roleStart(request);
        }
    }

    @ApiOperation(value = " 删除系统角色")
    @PostMapping("/role/delete")
    public Wrapper<Void> roleDelete(@RequestBody RoleStopRequest request) {
        synchronized (RoleController.class) {
            return roleService.roleDelete(request);
        }
    }

    @ApiOperation(value = " 查询角色详情")
    @GetMapping("/role/details")
    public Wrapper<RoleResponse> roleDetails(RoleStopRequest request) {
        return roleService.roleDetails(request);
    }

    /**
     * 查询角色权限菜单勾选的按钮Id列表
     * @param request 接口参数
     * @return 按钮Id列表
     */
    @RequestMapping(value = "/role/menu/button/list", method = RequestMethod.GET)
    public Wrapper<List<Long>> findRoleMenuButtons(@Valid RoleButtonRequest request) {
        return roleService.findRoleMenuButtons(request);
    }

    /**
     * 查询角色关联的会员审核（注册）流程列表
     * @param request 接口参数
     * @return 已配置的流程Id，以及所有会员审核（注册）流程列表
     */
    @RequestMapping(value = "/role/process/list", method = RequestMethod.GET)
    public Wrapper<PlatformProcessResponse> findPlatformProcesses(@Valid RoleIdRequest request) {
        return roleService.findPlatformProcesses(request);
    }

    /**
     * 新增或修改角色关联的会员审核（注册）流程列表
     * @param request 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/role/process", method = RequestMethod.POST)
    public Wrapper<Void> insertOrUpdateRolePlatformProcess(@RequestBody @Valid RolePlatformProcessRequest request) {
        return roleService.insertOrUpdateRolePlatformProcess(request);
    }
}
